//坐骑相关操作 
// {"属性":"敏捷","操作":"设置主属性","序列":1}
// {"序列":1,"操作":"放生"}
// {"位置":"F1","操作":"设置快捷键","类型":4}
// @ts-ignore
export const desc = {
    "name": "坐骑相关操作",
    "desc": "坐骑相关操作",
    "params_type": "无",
    "params": [
        {
            "en_name": "操作",
            "cn_name": "操作类型",
            "desc": "设置主属性/放生/设置快捷键",
            "example": "设置主属性"
        },
        {
            "en_name": "属性",
            "cn_name": "属性类型",
            "desc": "设置主属性生效",
            "example": "敏捷"
        },
        {
            "en_name": "序列",
            "cn_name": "序列",
            "desc": "坐骑序号",
            "example": "1"
        },
        {
            "en_name": "类型",
            "cn_name": "快捷键类型",
            "desc": "设置快捷键生效",
            "example": "F1"
        },
    ],
    "returns": [],
    "example": 'JGESDK:发送(11,{"属性":"敏捷","操作":"设置主属性","序列":1} {"序列":1,"操作":"放生"} {"位置":"F1","操作":"设置快捷键","类型":4})'
}
export async function execute(client_id, message_json) {
    let characters = G.Characters.get_current_login_characters(client_id);
    let option = message_json["操作"];
    switch (option) {
        case "设置主属性":
            set_master_attribute(client_id, characters, message_json);
            break;
        case "放生":
            remove_mounts(client_id, characters, message_json);
            break;
        case "设置快捷键":
            set_shortcut_key(client_id, characters, message_json);
            break;
        default:
            break;
    }
}

function set_master_attribute(client_id, characters, message_json) {
    let index = message_json["序列"] - 1;
    let attribute = message_json["属性"];
    let mounts_data = characters["坐骑列表"][index];
    if (mounts_data === undefined) {
        ClientUtils.send_basic_prompt(client_id, "#Y坐骑不存在");
        return;
    }
    mounts_data["主属性"] = attribute;
    ClientUtils.send_basic_prompt(client_id, "#G设置成功！");
    ClientUtils.send_client_message(client_id, 61, characters["坐骑列表"]);
}

function remove_mounts(client_id, characters, message_json) {
    let index = message_json["序列"] - 1;
    let mounts_data = characters["坐骑列表"][index];
    if (mounts_data === undefined) {
        ClientUtils.send_basic_prompt(client_id, "#Y坐骑不存在");
        return;
    }
    if (characters["坐骑"] !== null && mounts_data["认证码"] === characters["坐骑"]["认证码"]) {
        ClientUtils.send_basic_prompt(client_id, "#乘骑中无法放生");
        return;
    }
    characters["坐骑列表"].splice(index, 1);
    ClientUtils.send_basic_prompt(client_id, "#G放生成功！");
    ClientUtils.send_client_message(client_id, 61, characters["坐骑列表"]);
}

//类型=4,位置=序号
function set_shortcut_key(client_id, characters, message_json) {
    let key = message_json["位置"];
    G.Characters.set_set_shortcut_key(characters["id"], key, "飞行", 4);
    ClientUtils.send_basic_prompt(client_id, "#G设置成功");
}